package binaryTree;

import struct.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * 前序遍历
 * 中序遍历
 * 后序遍历
 * 层序遍历
 * @author: mayunfei
 * @date: 2025/1/5 17:19
 */
public class Traversal {

    private List<Integer> ans = new ArrayList<>();

    /**
     * 中序遍历
     * @param root
     * @return
     */
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root == null) return ans;
        inorderTraversalHelper(root);
        return ans;
    }

    private void inorderTraversalHelper(TreeNode node) {
        if (node == null) return;
        inorderTraversalHelper(node.left);
        ans.add(node.val);
        inorderTraversalHelper(node.right);
    }
}
